package com.example.video_player;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.PixelFormat;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaSync;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;

import java.io.File;
import java.io.IOException;

public class Main2Activity extends AppCompatActivity {
    Button back;
    MediaPlayer mPlayer;
    VideoView videoView;
    int position;
    Intent intent;
    String path;
    MediaController mController;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        intent = getIntent();
        path = (String) intent.getSerializableExtra("path");
        File video=new File(path);
        super.onCreate(savedInstanceState);
        getWindow().setFormat(PixelFormat.TRANSLUCENT);
        setContentView(R.layout.activity_main2);
        videoView = (VideoView) findViewById(R.id.video);
        // 创建MediaController对象
        mController = new MediaController(this);
        mPlayer = new MediaPlayer();
        back = (Button) findViewById(R.id.back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        if(video.exists())
        {
            videoView.setVideoPath(video.getAbsolutePath());  //①
            // 设置videoView与mController建立关联
            videoView.setMediaController(mController);  //②
            // 设置mController与videoView建立关联
            mController.setMediaPlayer(videoView);  //③
            // 让VideoView获取焦点
            videoView.requestFocus();
        }
    }
}